package com.heima.article.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.model.article.pojos.ApArticleConfig;
import com.heima.model.wemedia.dtos.WmNewsDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
@Transactional
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {
    @Override
    public void downOrUp(String message) {
        WmNewsDto wmNewsDto = JSONUtil.toBean(message, WmNewsDto.class);
        ApArticleConfig apArticleConfig = getById(wmNewsDto.getArticleId());
        apArticleConfig.setIsDown(ObjectUtil.equal(wmNewsDto.getEnable(), Convert.toShort(1)));
        this.updateById(apArticleConfig);
    }
}
